package cn.ecut.Servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.ecut.Dao.ApplyDao;
import cn.ecut.Bean.Apply;

@WebServlet("/ApplyServlet")
public class ApplyServlet extends HttpServlet {


    public ApplyServlet() {
        super();
    }

    public void destroy() {
        super.destroy();
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        this.doPost(request, response);
    }


    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");    //设置请求数据的字符编码格式
        String name = request.getParameter("RentUser"); //获得请求表单中的用户名
        String id = request.getParameter("NumUser");//获得请求表单中的密码
        String buildname = request.getParameter("room");
        String floorname = request.getParameter("RoomNum");
        String roomname = request.getParameter("RoomName");
        String shopname = request.getParameter("BedName");
        String sex = request.getParameter("sex");
        String phone = request.getParameter("phone");
        Apply apply = new Apply();
        apply.setName(name);
        apply.setId(id);
        apply.setBuildname(buildname);
        apply.setFloorname(floorname);
        apply.setRoomname(roomname);
        apply.setShopname(shopname);
        apply.setSex(sex);
        apply.setPhone(phone);
        ApplyDao ud = new ApplyDao();
        if(ud.apply(apply)){
            request.getRequestDispatcher("index.jsp").forward(request, response);
        }
        else {
            response.sendRedirect("index2.jsp");
        }
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
        // Put your code here
    }
}